package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.EmpMapper;
import com.itheima.mapper.LogMapper;
import com.itheima.pojo.Emp;
import com.itheima.pojo.Log;
import com.itheima.pojo.PageResult;
import com.itheima.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl extends ServiceImpl<LogMapper,Log> implements LogService {
    @Autowired
    private LogMapper logMapper;
    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageResult<Log> logCount(Integer page,Integer pageSize) {
        Page<Log> logPage = new Page<>(page,pageSize);
        logPage = page(logPage,null);
        List<Log> logs = logPage.getRecords();
        if (logs.size()>0){
            logs.forEach((log)->{
                Integer operateEmpId = log.getOperateEmpId();
                Emp emp = empMapper.selectById(operateEmpId);
                if(emp!=null){
                    log.setOperateEmpName(emp.getName());
                }
            });
        }


        return new PageResult(logPage.getTotal(),logPage.getRecords());
    }

}
